from django import forms

from App.bootstrap import BootStrapModelForm
from App.models import Employee


class EmployeeForm(BootStrapModelForm):
    name_employee = forms.CharField(
        label='外聘名',
        widget=forms.TextInput(attrs={
            'placeholder': '请输入外聘人姓名',
        })
    )

    prize_employee = forms.CharField(
        label='价格',
        widget=forms.TextInput(attrs={
            'placeholder': '请输入价格',
        })
    )

    phone_employee = forms.CharField(
        min_length=11,
        max_length=11,
        label='联系电话',
        widget=forms.TextInput(attrs={
            'placeholder': '请输入联系电话',
        })
    )

    img_index = forms.ImageField(
        label='主页宣传图',
    )

    img_employee = forms.ImageField(
        label='详情图',
    )

    type_employee = forms.ChoiceField(
        label='雇员类型',
        choices=(
            ("主持", "主持"),
            ("傧相", "傧相"),
            ("摄影师", "摄影师"),
            ("摄像师", "摄像师"),
            ("化妆师", "化妆师"),
            ("礼服", "礼服"),
            ("喜礼", "喜礼"),
            ("车队", "车队"),
            ("婚礼管家", "婚礼管家"),
        ),
    )
    video_employee = forms.FileField(
        label='宣传视频',
        required=False,
    )

    class Meta:
        model = Employee
        fields = '__all__'

    # 判断视频格式
    def clean_video_employee(self):
        file_object = self.cleaned_data.get('video_employee')
        # print(file_object.split('.'))
        if file_object.name.split('.')[-1] not in ['avi', 'wmv', 'mpeg', 'mp4', 'mov', 'rm', 'ram']:
            raise forms.ValidationError('文件格式错误')
        else:
            return file_object